/*----------------------------------------------------------------------
  - File name      : STC8Ax_WDT.c
  - Author         : Quark Team
  - Update date    : 2020-08-15                   
  -	Copyright      : Gevico Electronic studio   
  - Module comments: Watchdog module.
-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------
|                               INCLUDES                                |
-----------------------------------------------------------------------*/
#include "STC8Ax_WDT.h"
/*-----------------------------------------------------------------------
|                                 DATA                                  |
-----------------------------------------------------------------------*/
extern uint32 SYSCLK_FRE;
/*-----------------------------------------------------------------------
|                               FUNCTION                                |
-----------------------------------------------------------------------*/

/*--------------------------------------------------------
| @Description: WDT initialization function              |
| @param      : uint8 WDTPS, FUNSTATE State              |
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE WDT_Init(uint8 CLKDiv, FUNSTATE State)
{
	WDT_CONTR = CLKDiv;
	if(State == ENABLE) WDT_CONTR |= 0x20;
	else WDT_CONTR &= 0xDF;
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: Get WDT  feeding time function           |
| @param      : None                                     |
| @return     : None                                     |
--------------------------------------------------------*/

uint32 Get_WDT_Time(void)
{
	uint8 i;
	uint32 Dat = 2;
	for(i=0; i<(WDT_CONTR & 0x03); i++){ Dat *= 2; }
	Dat = (12 * 32768 * Dat) / SYSCLK_FRE;
	return Dat;
}


/*-----------------------------------------------------------------------
|          END OF FLIE        (C) COPYRIGHT Gevico Electronics          | 
-----------------------------------------------------------------------*/
